package JavaSE.TCPUDPLearning.OneToOne;

import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.Scanner;

public class Person {
    public static void main(String[] args) throws SocketException {
        System.out.println("请输入IP地址最后的数字（例如：192.168.5.xx，则输入：xx）：");
        Scanner in = new Scanner(System.in);
        String IPAddress = "192.168.5."+in.nextLine();
        //String IPAddress = "127.0.0.1";
        System.out.println("请输入端口号");
        int port = in.nextInt();
        // 将输入的端口号传入Socket套接字
        DatagramSocket UDPSocket = new DatagramSocket(port);
        SendTaskImpl sendTask = new SendTaskImpl(UDPSocket, IPAddress, port);
        ReceiveTaskImpl receiveTask = new ReceiveTaskImpl(UDPSocket, IPAddress, port);
        // 创建任务对象
        Thread sendThread = new Thread(sendTask);
        Thread receiveThread = new Thread(receiveTask);
        // 调用start()方法启动线程
        sendThread.start();
        receiveThread.start();

    }
}
